/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.controllers;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author ben
 */
@Stateless
public class CrudUtil {

    @PersistenceContext(unitName = "PaymentQR-CodesPU")
    private EntityManager em;

    public void persist(Object object) {
        try {
            em.persist(object);
            em.flush();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public boolean update(Object o) {
        try {
            em.merge(o);
            em.flush();
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    public boolean delete(Object o) {
        try {
            em.remove(em.merge(o));
            em.flush();
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
}
